package com.juanLL.CMC.models;

import android.graphics.Bitmap;
import android.graphics.Rect;

/**
 * Model class that contains the basic variables and methods needed to represent
 * a game object in the game
 * 
 * 
 */
public class Model implements Cloneable {

	// bitmap representation of the object
	public Bitmap bitmap;
	// object hitbox
	public Rect hitbox = new Rect();
	// draw flag
	public Boolean draw = false;
	// type id
	public int type;
	// position in the x axis
	public float x;
	// position in the y axis
	public float y;
	// speed in the x axis
	public float xSpeed;
	// speed in the y axis
	public float ySpeed;
	// the current state id
	public int state;

	// type id constants
	public static final int TYPE_ORGANIC = 0;
	public static final int TYPE_PLASTIC = 1;
	public static final int TYPE_GLASS = 2;
	public static final int TYPE_CITIZEN = 3;
	public static final int TYPE_RAT = 4;

	/**
	 * getBitmap, bitmap getter
	 * 
	 * @return the object's bitmap
	 */
	public Bitmap getBitmap() {
		return bitmap;
	}

	/**
	 * update method, updates the position of the object.
	 */
	public void update() {
		// update x position
		x += xSpeed;
		// update y position
		y += ySpeed;

	}

	/**
	 * getHitbox method, creates a Rect around the current position
	 * 
	 * @return Rect around the current position
	 */
	public Rect getHitbox() {

		hitbox.set((int) x, (int) y, (int) x + bitmap.getWidth(), (int) y
				+ bitmap.getHeight());
		return hitbox;
	}

	/**
	 * getHitboxBigger method, returns a bigger hitbox around the object to
	 * facilitate touch detection.
	 * 
	 * @return
	 */
	public Rect getHitboxBigger() {
		hitbox.set((int) x - 100, (int) y - 100, (int) x + bitmap.getWidth()
				+ 100, (int) y + bitmap.getHeight() + 100);
		return hitbox;

	}

	public Rect getHitboxSmaller() {
		hitbox.set((int) x + 5, (int) y + 5, (int) x + bitmap.getWidth() - 5,
				(int) y + bitmap.getHeight() - 5);
		return hitbox;
	}

	@Override
	public Object clone() {
		// TODO Auto-generated method stub
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
